package com.example.fill;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

public class ScrollGroup extends ViewGroup {
    private float mScrollX = 0;
    private float mScrollY = 0;

    public ScrollGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int childCount = getChildCount();
        if (childCount != 1) return;
        View childAt = getChildAt(0);
        measureChild(childAt, Integer.MAX_VALUE, heightMeasureSpec);
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int childCount = getChildCount();
        if (childCount != 1) return;
        View childAt = getChildAt(0);
        childAt.layout(0, 0, childAt.getMeasuredWidth(), childAt.getMeasuredHeight());
    }

//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        switch (event.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                mScrollY = event.getY();
//                mScrollX = event.getX();
//                break;
//            case MotionEvent.ACTION_MOVE:
//                float y = event.getY();
//                float x = event.getX();
//                float distanceY = mScrollY - y;
//                float distanceX = mScrollX - x;
//                scrollBy((int) distanceX, (int) distanceY);
//                mScrollY = y;
//                mScrollX = x;
//                break;
//            case MotionEvent.ACTION_UP:
//            case MotionEvent.ACTION_CANCEL:
//
//                break;
//        }
//        return true;
//    }
}
